import lombok.Data;
import cn.jolyoulu.common.poi.excel.annotation.ExcelImport;
import cn.jolyoulu.common.poi.excel.reader.handler.drawing.AbsDrawingReaderHandler;
import cn.jolyoulu.common.poi.excel.reader.sax.SaxDrawingReaderHandler;
import cn.jolyoulu.common.poi.excel.reader.sax.SaxExcelReader;

import java.io.*;
import java.time.LocalDate;
import java.util.List;

/**
 * @Author: JolyouLu
 * @Date: 2023/12/17 21:14
 * @Description
 */
public class SaxExcelReaderTest {
    public static void main(String[] args) throws FileNotFoundException {
        File file = new File("C:\\Users\\JolyouLu\\Downloads\\工作簿1.xlsx");
        SaxExcelReader
                .of(ImpEntity.class)
                .sheet(0, 2)
                .read(file,2, dataList -> {

                });
        List<ImpEntity> read = SaxExcelReader
                .of(ImpEntity.class)
                .sheet(0, 1)
                .read(file);
        System.out.println(read);
        SaxExcelReader
                .of(ImpEntity.class)
                .sheet(0, 2)
                .readImages(file, new AbsDrawingReaderHandler() {
                    @Override
                    public void handler(Integer row, Integer column, SaxDrawingReaderHandler.Image value) {
                        System.out.println(row);
                        System.out.println(column);
                        try(FileOutputStream stream = new FileOutputStream("C:\\Users\\JolyouLu\\Downloads\\aa." + value.getSuffix())) {
                            stream.write(value.getBytes());
                        } catch (FileNotFoundException e) {
                            throw new RuntimeException(e);
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                        System.out.println(value);
                    }
                });
    }

    @Data
    public static class ImpEntity {
        @ExcelImport(titleIndex = 1)
        private String name;
        @ExcelImport(titleIndex = 2)
        private String sex;
        @ExcelImport(titleIndex = 3)
        private LocalDate birthday;
        @ExcelImport(titleIndex = 4)
        private Double num;
        @ExcelImport(titleIndex = 5)
        private Integer age;
    }
}
